<!DOCTYPE html>

<html>

<head>

    <title>收获地址</title>

    <include file='public/head'>

    <style>

        .layui-legend-size{font-size:14px !important;}

        .layui-nopadding{padding:0 !important;}

        .layui-overflow{overflow:auto;}

        .layui-nomargin{margin: 0 !important;}

        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}

        .layui-input{height:30px !important; }

        .layui-form-search-item .layui-inline{margin-bottom: 5px;} 

        .layui-form-search-item label{margin-left: 15px;}

        .layui-table-page {padding: 7px 0px 0px;}

        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}

    </style>        

</head>

<body>

<div class="layui-tab " lay-filter="demo-tab">

    <!-- 顶部导航菜单开始 -->

    <div class="layui-tab-nav" >

        <ul class="layui-tab-title">

            {:getNav('member','ship_address/index')};

        </ul>

    </div>



        <fieldset class="layui-elem-field layui-field-title layui-field-padding">

            <legend class="layui-legend-size">搜索</legend>

            <form class="layui-form table-bar" action="{:cmf_plugin_url('Member://ship_address/index')}" lay-filter="form-bar" method="post">

                <div class="layui-form-item" style="margin-bottom: 0px;">

                    <div class="layui-inline ">

                        <div class="layui-input-inline " style="width: 100px;">



                            <select name="stype" lay-filter="module_name">

                                <option value="0" <?php if(isset($data['stype']) && $data['stype']==''){echo 'selected'; } ?>  >请选择</option>

                                <option value="1" <?php if(isset($data['stype']) && $data['stype']==1){echo 'selected'; } ?>  >收件人名称</option>

                                <option value="2" <?php if(isset($data['stype']) && $data['stype']==2){echo 'selected'; } ?>  >收件人电话</option>

                                <option value="3" <?php if(isset($data['stype']) && $data['stype']==3){echo 'selected'; } ?>  >用户uid</option>

                                <option value="4" <?php if(isset($data['stype']) && $data['stype']==4){echo 'selected'; } ?>  >收件地区代码</option>

                                <option value="5" <?php if(isset($data['stype']) && $data['stype']==5){echo 'selected'; } ?>  >收件详细地址</option>

                            </select>

                        </div>

                    </div>



                    <div class="layui-inline ">

                        <div class="layui-input-inline "  >

                            <input type="text" class="layui-input" name="keyword" style="width:200px;" value="{$data['keyword']|default=''}" placeholder="输入关键词"/>

                        </div>

                    </div>

                    <div class="layui-inline">

                        <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>

                    </div>

                </div>

            </form>

        </fieldset>



        

		



        <div class="layui-card">

        <div class="layui-card-header layui-bg-gray layui-bottom">



            <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger batch-delete" onclick="del_all();"> 批量删除</a>



            <a href="javascript:;" class="layui-btn layui-btn-xs add-btn" onclick="addAddress();"><i class="layui-icon">&#xe654;</i>添加新收货地址</a>

        </div>

        <div class="layui-card-body layui-nopadding " >

            <form method="post" id="f">

            <table  class="layui-table layui-nomargin" >

                <thead>

                    <tr>

                        <th style="text-align:center;">

                            <input type='checkbox' id='check-box-all'>

                        </th>

                        <th style="text-align:center;">id</th>

                        <th style="text-align:center;">用户uid</th>

                        <th style="text-align:center;">收件人名称</th>

                        <th style="text-align:center;">收件人电话</th>

                        <th style="text-align:center;">收件地区代码</th>

                        <th style="text-align:center;">收件地区名称</th>

                        <th style="text-align:center;">收件详细地址</th>

                        <th style="text-align:center;">邮政编码</th>

                        <th style="text-align:center;">是否为默认收货地址</th>

                        <th style="text-align:center;">操作</th>

                    </tr>

                </thead>

                <tbody>

                    <volist name="list" id="vo" >

                        <tr> 

                            <td>

                                <input type="checkbox" class='check-box' name='id[]' value='{$vo.id}'>

                            </td>

                            <td>{$vo.id}</td>

                            <td>{$vo.uid}</td>

                            <td>{$vo.receive_name}</td>

                            <td>{$vo.receive_phone}</td>

                            <td>{$vo.cri_code}</td>

                            <td>{$vo.cri_name}</td>

                            <td>{$vo.address}</td>

                            <td>{$vo.postal_code}</td>

                            <td>

                                <switch name="vo.is_default">

                                    <case value="1"><a style="text-decoration:none;color:orange;">是</a></case>

                                    <case value="2"><a style="text-decoration:none;color:gray;">否</a></case>

                                </switch>

                            </td>

                            <td>

                                <div class="layui-btn-group">

                                    <a class="layui-btn layui-btn-primary layui-btn-xs" onclick="editAddress({$vo.id})">

                                        <i class="layui-icon">&#xe642;</i>

                                    </a>

                                    <a href="javascript:void(0);" class="layui-btn layui-btn-primary layui-btn-xs btn-delete" data-id="{$vo.id}">

                                        <i class="layui-icon">&#xe640;</i>

                                    </a>

                                </div>

                            </td>

                        </tr>

                    </volist>

                </tbody>

            </table>

            </form>

            <div class="layui-table-page">

                <div id="layui-table-page1">

                    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">

                        {$page|default=''}

                    </div>

                </div>

            </div>

        </div>

    </div>



</div>



<include file="public/scripts"/>



<script type="text/javascript">



//全选/取消

$('#check-box-all').on('click',function(){  

    $('.check-box').prop('checked',$('#check-box-all').prop('checked'));

});



//单个删除

$('.btn-delete').on('click',function(){

    let id = $(this).data('id');

    let text = "确定要删除吗?";

    let url = "{:cmf_plugin_url('Member://ship_address/delAddress')}?id="+id;



    layer.confirm(text, {icon: 3, title:'提示', btn: ['删除','取消']}, function(index,layero){

        $.ajax({

            url: url,

            success:function(data){

                if(data.code==1){

                    layer.msg(data.msg,{icon:1,time:1500},function(){

                        window.location.reload();

                    });

                }else{

                    layer.msg(data.msg,{icon:2,time:1500});

                }

            },

            error:function(){

                layer.msg('系统错误！',{icon:2,time:1500});

            }

        })

    },function(index){

        // alert('取消');

    });

})



//批量删除

function del_all(){



    let text = "确定要删除吗?";

    let url = "{:cmf_plugin_url('Member://ship_address/delAddress')}";



    layer.confirm(text, {icon: 3, title:'提示', btn: ['删除','取消']}, function(index,layero){

        $.ajax({

            url: url,

            data: $('#f').serialize(),

            success:function(data){

                if(data.code==1){

                    layer.msg(data.msg,{icon:1,time:1500},function(){

                        window.location.reload();

                    });

                }else{

                    layer.msg(data.msg,{icon:2,time:1500});

                }

            },

            error:function(){

                layer.msg('系统错误！',{icon:2,time:1500});

            }

        })

    },function(index){

        // alert('取消');

    });

}



</script>



<script type="text/javascript">



    /**

     * 添加新收货地址

     */

    function addAddress(){

        let addpageurl = "{:cmf_plugin_url('Member://ship_address/addPage')}";

        let addurl = "{:cmf_plugin_url('Member://ship_address/add')}";

        layer.open({

            type: 2,

            title: '添加新收货地址',

            shadeClose: true,

            shade: 0.8,

            area: ['800px', '500px'],

            btn:['提交','关闭'],

            fixed:false,

            content: addpageurl, //iframe的url

            yes:function(index, layero){

                var body = layer.getChildFrame('body', index); 

                

                //parentInfo = window["layui-layer-iframe" + index].callbackdata();

                //console.log(parentInfo);

                



                var list = body.find(".sort");

                var data=new Array();

                var key=new Array();

                var value=new Array();

                for(var i=0;i<list.length && list[i];i++)

                {

                    key[i] = list[i].id;

                    value[i] = list[i].value;

                }



                var uid = body.find('input[name=uid]').val();

                var receive_name = body.find('input[name=receive_name]').val();

                var receive_phone = body.find('input[name=receive_phone]').val();

                var address = body.find('input[name=address]').val();

                var postal_code = body.find('input[name=postal_code]').val();



                if(uid==''){

                    layer.msg('uid不可为空', function(){

                    });

                    return false;

                }

                if(receive_name==''){

                    layer.msg('收件人名称不可为空', function(){

                    });

                    return false;

                }

                if(receive_phone==''){

                    layer.msg('收件人电话不可为空', function(){

                    });

                    return false;

                } 

                if(address==''){

                    layer.msg('详细地址不可为空', function(){

                    });

                    return false;

                } 

                if(key==''){

                    layer.msg('收件地区尚未选择', function(){

                    });

                    return false;

                } 

                

                $.ajax({   

                    url:addurl,

                    type:'post',

                    data:{  

                           uid : uid,  

                           receive_name : receive_name,  

                           receive_phone : receive_phone,

                           address : address,

                           postal_code : postal_code,

                           key : key,

                           value : value,

                    },  

                    dataType:'json',

                    success:function(datas){

                        console.log(datas);

                        console.log('datas');

                        if(datas.status=='success'){

                            layer.msg(datas.message,{time:1500},function(){

                                layer.closeAll();

                                window.location.reload(); 

                            });

                        }else if(datas.status=='error'){

                            console.log('BB');

                            layer.msg(datas.message);

                        }

                    },

                    error:function(data){

                        layer.msg('添加失败');

                        return false;

                    }

                })

            }



        });

    }

</script>

<script type="text/javascript">



    /**

     * 修改收货地址

     */

    function editAddress(data){

        let addpageurl = "{:cmf_plugin_url('Member://ship_address/editPage')}?id="+data;
        console.log(addpageurl);
        let addurl = "{:cmf_plugin_url('Member://ship_address/edit')}";

        layer.open({

            type: 2,

            title: '添加新收货地址',

            shadeClose: true,

            shade: 0.8,

            area: ['800px', '500px'],

            btn:['提交','关闭'],

            fixed:false,

            content: addpageurl, //iframe的url

            yes:function(index, layero){

                var body = layer.getChildFrame('body', index); 



                //parentInfo = window["layui-layer-iframe" + index].callbackdata();

                //console.log(parentInfo);

                



                var list = body.find(".sort");

                var data=new Array();

                var key=new Array();

                var value=new Array();

                for(var i=0;i<list.length && list[i];i++)

                {

                    key[i] = list[i].id;

                    value[i] = list[i].value;

                }







                var id = body.find('input[name=id]').val();

                var uid = body.find('input[name=uid]').val();

                var receive_name = body.find('input[name=receive_name]').val();

                var receive_phone = body.find('input[name=receive_phone]').val();

                var address = body.find('input[name=address]').val();

                var is_default = body.find('select[name=is_default]').val();

                var postal_code = body.find('input[name=postal_code]').val();



                //alert(cstaus);



                if(uid==''){

                    layer.msg('uid不可为空', function(){

                    });

                    return false;

                }

                if(receive_name==''){

                    layer.msg('收件人名称不可为空', function(){

                    });

                    return false;

                }

                if(receive_phone==''){

                    layer.msg('收件人电话不可为空', function(){

                    });

                    return false;

                } 

                if(address==''){

                    layer.msg('详细地址不可为空', function(){

                    });

                    return false;

                } 

                

                $.ajax({   

                    url:addurl,

                    type:'post',

                    data:{  

                           id : id,  

                           uid : uid,  

                           receive_name : receive_name,  

                           receive_phone : receive_phone,

                           address : address,

                           postal_code : postal_code,

                           key : key,

                           value : value,

                           is_default : is_default,

                    },  

                    dataType:'json',

                    success:function(datas){

                        console.log(datas);

                        console.log('datas');

                        if(datas.status=='success'){

                            layer.msg(datas.message,{time:1500},function(){

                                layer.closeAll();

                                window.location.reload(); 

                            });

                        }else if(datas.status=='error'){

                            console.log('BB');

                            layer.msg(datas.message);

                        }

                    },

                    error:function(data){

                        layer.msg('添加失败');

                        return false;

                    }

                })

            }



        });

    }

</script>





</body>